/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Server.domain;

import java.util.LinkedList;

/**
 *
 * @author user
 */
public class PlayerList
{
	//player list
	protected LinkedList<Player> list = new LinkedList<Player>();
	

	public void advance(float elapsedTime)
	{
		for(int x=list.size()-1;x>=0;x--)
		{
			list.get(x).advance(elapsedTime);
			if(list.get(x).getKick())
			{
				System.out.println(list.get(x).getName()+" Timed Out");
				list.remove(x);
			}
		}
	}
	public String toString()
	{
		String info = "";
		Player player;
		for(int x=0;x<list.size();x++)
		{
			player = list.get(x);
			info += player.getName()+" x "+(int)player.getX()+" y "+(int)player.getY()+" ";
		}
		return info;
	}
	
	public Player getByName(String n)
	{
		for(int x=0;x<list.size();x++)
		{
			if(list.get(x).getName().equals(n))
			{
				return list.get(x);
			}
		}
		list.add(new Player(n));
		return list.get(list.size()-1);
	}
	public Player getPlayer(int index)
	{
		return list.get(index);
	}
	public int size()
	{
		return list.size();
	}

    public void add(Player player) {
        list.add(player);
    }
}
